var t = getApp(), e = require("../../../../utils/themeSkin/skinBehavior"), a = !0;

Page({
    behaviors: [ e ],
    data: {
        sell_value: "",
        sell_id: "",
        poundage: 0,
        trading_limit: 0,
        trading_fold: 0,
        love_name: "",
        usable: 0,
        rate: 0,
        isTransformLoveV: !1,
        balanceLang: "余额"
    },
    onLoad: function(t) {
        "transformLoveV" == t.name && this.setData({
            isTransformLoveV: !0
        }), this.getUsable(), this.getLove();
        try {
            var e = wx.getStorageSync("balance");
            e && this.setData({
                balanceLang: e
            });
        } catch (t) {}
    },
    onReady: function() {},
    onShow: function() {
        a = !0;
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    allConversion: function() {
        this.setData({
            sell_value: this.data.usable
        });
    },
    getUsable: function() {
        var e = this;
        if (this.data.isTransformLoveV) {
            var a = t.getNetAddresss("plugin.love.Frontend.Controllers.page.index");
            t._getNetWork({
                url: a,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? (e.setData({
                        love_name: a.data.love_name
                    }), console.log(e.data.themeBaseColor, "ddddddddd"), wx.setNavigationBarColor({
                        frontColor: "#ffffff",
                        backgroundColor: e.data.themeBaseColor,
                        animation: {
                            duration: 400,
                            timingFunc: "easeIn"
                        }
                    })) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else {
            var o = t.getNetAddresss("finance.balance.conver");
            t._getNetWork({
                url: o,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? (e.setData({
                        usable: a.data.credit2,
                        rate: a.data.rate,
                        rate_1: Math.floor(100 * a.data.rate / 100 * 100) / 100,
                        rate_2: Math.floor(e.data.sell_value * a.data.rate / 100 * 100) / 100
                    }), wx.setNavigationBarColor({
                        frontColor: "#ffffff",
                        backgroundColor: e.data.themeBaseColor,
                        animation: {
                            duration: 400,
                            timingFunc: "easeIn"
                        }
                    })) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    getLove: function() {
        try {
            var e = wx.getStorageSync("yz_basic_info");
            if (e) {
                var a = e.home;
                a.designer.love_name && this.setData({
                    love_name: a.designer.love_name
                }), wx.setNavigationBarTitle({
                    title: "转化" + a.designer.love_name
                });
            }
        } catch (t) {}
        if (this.data.isTransformLoveV) {
            var o = this, n = t.getNetAddresss("plugin.love.Frontend.Modules.Trading.Controllers.trading.get-sell-love");
            t._getNetWork({
                url: n,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (o.setData({
                        usable: e.data.love.usable,
                        poundage: e.data.set.poundage,
                        trading_limit: e.data.set.trading_limit,
                        trading_fold: e.data.set.trading_fold
                    }), e.data.set.trading_fetter && o.setDtaa({
                        trading_fetter: e.data.set.trading_fetter
                    })) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    sellValueinp: function(t) {
        var e = t.detail.value;
        this.setData({
            sell_value: e,
            rate_2: Math.floor(e * this.data.rate / 100 * 100) / 100
        });
    },
    saleBalance: function() {
        var e = this;
        if (!this.data.isTransformLoveV || this.data.sell_value) {
            if (a) if (a = !1, this.data.isTransformLoveV) {
                var o = t.getNetAddresss("plugin.love.Frontend.Modules.Trading.Controllers.trading.save-sell-love");
                t._getNetWork({
                    url: o,
                    data: {
                        amount: this.data.sell_value
                    },
                    success: function(t) {
                        var o = t.data;
                        1 == o.result ? (setTimeout(function() {
                            a = !0;
                        }, 1e3), wx.showToast({
                            icon: "none",
                            title: o.msg,
                            duration: 1500
                        }), e.setData({
                            sell_value: ""
                        }), e.getLove()) : (a = !0, wx.showToast({
                            icon: "none",
                            title: o.msg,
                            duration: 1500
                        }));
                    },
                    fail: function(t) {
                        setTimeout(function() {
                            a = !0;
                        }, 1e3), console.log(t);
                    }
                });
            } else {
                var n = t.getNetAddresss("finance.balance.convert-love-value");
                t._getNetWork({
                    url: n,
                    data: {
                        convert_amount: this.data.sell_value
                    },
                    success: function(t) {
                        var o = t.data;
                        1 == o.result && (setTimeout(function() {
                            a = !0;
                        }, 1e3), 1 === o.result ? (wx.showToast({
                            icon: "none",
                            title: o.msg,
                            duration: 1500
                        }), e.setData({
                            sell_value: ""
                        }), e.getUsable()) : wx.showToast({
                            icon: "none",
                            title: o.msg,
                            duration: 1500
                        }));
                    },
                    fail: function(t) {
                        setTimeout(function() {
                            a = !0;
                        }, 1e3), console.log(t);
                    }
                });
            }
        } else wx.showToast({
            icon: "none",
            title: "请输入您要出售的数额",
            duration: 1500
        });
    }
});